<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>网站后台管理模版</title>
    <link rel="stylesheet" href="../../assets/libs/layui/css/layui.css">
</head>

<body>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="add">添加职员信息</button>
		<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
		<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
		<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
	</div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>

<script src="../../assets/libs/layui/layui.js"></script>
<script src="../../assets/js/my.js"></script>
<script>
    layui.use(['table', 'jquery', 'layer'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer


        table.render({
            elem: '#test'
            , url: '/employeeservlet/list'
            , toolbar: '#toolbarDemo'
            , title: '员工数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'eId', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true}
                , {field: 'eName', title: '职员姓名', width: 120, edit: 'text'}

                , {field: 'eGender', title: '性别', width: 80, edit: 'text', sort: true}
                , {field: 'eAge', title: '年龄', width: 80, edit: 'text', sort: true}
                , {field: 'eBirthday', title: '生日', width: 80, edit: 'text', sort: true}
                , {field: 'eJob', title: '职位', width: 150, edit: 'text'}
                , {field: 'eLocation', title: '现工作地点', width: 80, edit: 'text'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
            ]]
            , page: true
        });

		//头工具栏事件
		table.on('toolbar(test)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
			switch(obj.event){
                case 'add':
                    layer.open({
                        type:2,
                        content:['menu2-add.html'],
                        area:['600px','400px'],
                        maxmin:true,
                        cancel:function (index){
                            $(".layui-laypage-btn").click();//这里用于关闭Open时触发回调函数  刷新父页面数据  一定要引入Jquery
                        }
                    })
                    break;
				case 'getCheckData':
					var data = checkStatus.data;
					layer.alert(JSON.stringify(data));
					break;
				case 'getCheckLength':
					var data = checkStatus.data;
					layer.msg('选中了：'+ data.length + ' 个');
					break;
				case 'isAll':
					layer.msg(checkStatus.isAll ? '全选': '未全选');
					break;
			};
		});

		//监听行工具事件
		table.on('tool(test)', function(obj){
			var data = obj.data;
			//console.log(obj)
			if(obj.event === 'del'){
				layer.confirm('真的删除么', function(index){
					obj.del();
					layer.close(index);
					// alert(data.uId);
					$.get(host+'/employeeservlet/removeById',{eId:data.eId},function (r) {
						if(r.code==0){
							layer.msg("删除成功");
						}else{
							layer.msg("删除失败");
						}
					},'json')
				});
			} else if(obj.event === 'edit'){
				layer.open({
                    type:2,
                    content:['EmployeeUpdate.html'],
                    area:['600px','400px'],
                    maxmin:true,
                        success:function (layero, index) {
                            var body = layer.getChildFrame('body', index);
                            body.find("#eId").val(data.eId);
                            body.find("#eName").val(data.eName);
                            body.find("#eGender").val(data.eGender);
                            body.find("#eAge").val(data.eAge);
                            body.find("#eJob").val(data.eJob);
                            body.find("#date1").val(data.eBirthday);
                            body.find("#eLocation").val(data.eLocation);
                        },
                    cancel:function (index){
                        $(".layui-laypage-btn").click();//这里用于关闭Open时触发回调函数  刷新父页面数据  一定要引入Jquery
                    },

                })
			}
		});

    });
</script>
</html>